<template>
	<!--我的动态-->
	<view class="page-content">
		<scroll-view class="page-body" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
			<!--动态-->
			<template v-if="datalist && datalist.length > 0 ">
				<block v-for="(item,index) in datalist" :key="index">
					<view class="body-box">
						<dynamicInfo :obj="item" dynType="user" @checked="checked" @deleted="deleted"
							@comment="comment">
						</dynamicInfo>
					</view>
				</block>
				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
		</scroll-view>
		<!--弹窗-->
		<w-popup :show="showtip" :type="type1" @change="change1">
			<view class="w-tip">
				<view class="w-con">
					<view class="txt-row">是否确认删除？</view>
				</view>
				<view class="w-but">
					<view class="w-but-txt" @click="cancel('tip')">取消</view>
					<view class="w-but-txt" @click="confirm">确认</view>
				</view>
			</view>
		</w-popup>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from "vuex";
	import {
		getUserInfos,editUserInfos,getOssUploadsParams,
		getDynamicLists, //动态列表
		getReplyLists, //评论列表
		delDynamics, //删除评论
	} from '@/common/api.js'
	import loadMore from '@/components/uni-load-more/load-more.vue';
	import dynamicInfo from '@/pages/index/components/dynamic_info.vue'; //动态
	import wPopup from '@/components/w-popup/w-popup2.vue';// 弹窗
	export default{
		components: {
			loadMore,dynamicInfo,wPopup
		},
		data(){
			return {
				showtip: false, //是否显示弹窗2
				content1: '顶部弹 popup',
				type1: '', //弹窗显示方式
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				sel_data:[],
				fromdata: {
					company_id: '',
					type: '1',
					page: 1,
					limit: 99
				},
				sel_id:0,
				datalist: [{
					id: 1,
					head: '/static/data-img/data-tx.png',
					name: '流星',
					time: '2021/03/23',
					txt: '    今天采购了10本画册，哇这画册做的也太好看，这个设计师做的不错，我很喜欢他的风格。有喜欢的小伙伴也可以去看看！',
					stick_statu: 1,
					imgs: [{
						img: '/static/data-img/data-img1.png'
					}, {
						img: '/static/data-img/data-img2.png'
					}, {
						img: '/static/data-img/data-img3.png'
					}, {
						img: '/static/data-img/data-img4.png'
					}, {
						img: '/static/data-img/data-img5.png'
					}],
					message:[
						{
							name:'夏雨',
							uid:1,
							msg:'还不错',
							type:2
						},{
							name:'夏雨',
							msg:'是吧',
							type:1
						}
					]
				}, {
					id: 2,
					head: '/static/data-img/data-tx.png',
					name: '流星',
					time: '2021/03/23',
					txt: '    今天采购了10本画册，哇这画册做的也太好看，这个设计师做的不错，我很喜欢他的风格。有喜欢的小伙伴也可以去看看！',
					stick_statu: 1,
					imgs: [{
						img: '/static/data-img/data-img1.png'
					}, {
						img: '/static/data-img/data-img2.png'
					}, {
						img: '/static/data-img/data-img3.png'
					}, {
						img: '/static/data-img/data-img4.png'
					}, {
						img: '/static/data-img/data-img5.png'
					}]
				}]
			}
		},
		computed: {
			...mapGetters(['companyInfo', 'userInfo']),
		},
		onShow() {
			this.fromdata.company_id = this.companyInfo.id;
			this.getdata();
		},
		onLoad(option){
			console.log(222,option)
			if(option.type==='o'){
				this.type = option.type;
				this.id = option.id;
				
				/* if(this.datalist && this.datalist.length>0){
					let datalist = [];
					this.datalist.forEach(item =>{
						if(item.id === parseInt(option.id)){
							datalist.push(item)
						}
					})
					this.sel_data = datalist;
				} */
			}else{
				// /this.sel_data = this.datalist;
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(23,e)
			if (e.index == 0) {
				uni.navigateTo({
					url: '/pages/news/notificationEdit',
				})
			}
		},
		methods:{
			confirm(){
				delDynamics({id:this.sel_id}).then(res=>{
					if(res.code === 2000){
						uni.showToast({
							title:'删除成功！',
							icon:'none',
							duration:2000
						})
						this.getdata();
					}
				})
				this.showtip = false;
			},
			//获取数据
			async getdata(){
				await this.getDynamicList();
			},
			getDynamicList(){
				getDynamicLists(this.fromdata).then(res=>{
					if(res.code === 2000){
						this.datalist = res.data.data.map((item)=>({
							...item,
							message:[]
						}));
						console.log(333,this.datalist)
						if(this.datalist && this.datalist.length>0){
							this.datalist.forEach(item=>{
								getReplyLists({id:item.id}).then(res=>{
									if(res.code === 2000){
										item.message = res.data;
									}
								})
							})
						}
					}
				})
			},
			//评论
			forcomment(){
				
			},
			//删除
			deleted(id){
				this.showtip = true;
				this.content1 = 'center';
				this.type1 = 'center';
				this.sel_id = id;
			},
			loadmore(){
			},
			//取消
			cancel(){
				this.show = false
				this.showtip = false
			},
			change1(e) {
				if (!e.show) {
					this.showtip = false
				}
			},
		}
	}
</script>

<style lang="scss">
	/* 提示窗口 */
	.w-tip {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 70vw;
		border-radius: 10rpx;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		margin: 30rpx auto 0;
	
		.w-tit {
			font-size: 36rpx;
			font-weight: bold;
			color: $font-color-3;
			line-height: 60rpx;
			height: 60rpx;
			margin-top: 20rpx;
			text-align: center;
		}
	
		.w-but {
			display: flex;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-b3;
			height: 84rpx;
			line-height: 84rpx;
	
			.w-but-txt {
				flex: 1;
				text-align: center;
				border-right: 1rpx solid #f5f5f5;
			}
	
			.w-but-txt:last-of-type {
				border-right: none;
			}
		}
	
		.w-con {
			display: flex;
			text-align: center;
			font-weight: 400;
			padding: 40rpx 30rpx;
			border-bottom: 1rpx solid #f5f5f5;
			.txt-row{
				width: 100%;
				text-align: center;
				font-size: 28rpx;
				color: $font-color-9;
			}
		}
	}
	.page-content{
		width: 100vw;
		height: 100%;
		background: $uni-bg-color-grey;
		.page-body{
			display: flex;
			height: 100%;
			.body-box{
				display: flex;
				flex-direction: column;
				background: $uni-bg-color;
				padding-top: 30rpx;
			}
		}
	}

</style>
